// pages/user/account/accountRecord/accountRecord.js
const common = require('../../../../utils/util.js')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        recordList: [],
        recordType: 1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getRecordList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    getRecordList: function() {
        const that = this
        let recordList = this.data.recordList
        wx.showLoading({
            title: '加载中',
        })
        if (this.data.recordType == 1) {
            let data = {
                is_wait: 2
            }
            common.post('Wallet/money_detail', data).then(function(res) {
                wx.hideLoading()
                if (res.code == 204) {
                    that.setData({
                        recordList: recordList
                    })
                } else {
                    recordList = res
                    that.setData({
                        recordList: recordList
                    })
                }
            }).catch(function(e) {})
        } else {
            let data = {}
            common.post('Wallet/money_detail_out', data).then(function(res) {
                wx.hideLoading()
                if (res.code == 204) {
                    that.setData({
                        recordList: recordList
                    })
                } else {
                    recordList = res
                    that.setData({
                        recordList: recordList
                    })
                }
            }).catch(function(e) {})
        }
    },

    navClick: function(e) {
        if (this.data.recordType == e.currentTarget.dataset.type) {
            return
        }
        this.setData({
            recordType: e.currentTarget.dataset.type,
            recordList: []
        })
        this.getRecordList()
    },

    goHistory: function(){
        wx.navigateTo({
            url: '/pages/user/account/accountRecordHistory/accountRecordHistory'
        })
    }
})